﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/css/global.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/css/main.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/css/themes/default/easyui.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/css/themes/gray/tabs.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/css/themes/icon.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/css/plan.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.8.2.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.easyui.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/json3.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/plan.js")" type="text/javascript"></script>

    <script type="text/javascript">

        var displanPanel = function (displayID) {
            var displayPanel = $('#' + displayID);
            if (displayPanel.length) {
                $('.cycle_detail').hide();
                displayPanel.show();
            }
        };

        var toggleChooseDay = function () {
            var checked = $('#chooseDays').is(':checked');
            if (checked) {
                $('#numberRange').removeAttr('disabled');
            } else {
                $('#numberRange').attr('disabled', true).val(0);
            }
        };

        var enableControl = function (containerID) {
            var container = $('#' + containerID);
            var controls = container.find('input,select,textarea');
            controls.each(function () {
                $(this).removeAttr('disabled');
            });

            container.find('.easyui-datebox').datebox({ 'disabled': false });
            container.find('.validatebox-text').attr('disabled', true);
            container.find('.searchbox-button').show();
        };

        $(function () {

            toggleChooseDay();

            $('.easyui-datebox').datebox({
                formatter: function (date) {
                    return date.formate('yyyy-MM-dd')
                }
            });



            $('.combo-text').attr('disabled', true);

            $('input[type="radio"][name="cycle"]').bind('click', function (e) {
                var target = $(e.currentTarget);
                var displayID = target.attr('data-panel');
                displanPanel(displayID);
            });

            var selectedPanel = $('input[type="radio"][name="cycle"]:checked').attr('data-panel');
            displanPanel(selectedPanel);

            //全选
            $('input[type="checkbox"].list_all').bind('click', function () {
                var groupName = $(this).attr('name'),
                    items = $('input[type="checkbox"][name="' + groupName + '"].list_item'),
                    status = $(this).is(':checked');

                if (status) {
                    items.attr('checked', 'checked');
                } else {
                    items.removeAttr('checked');
                }

            });

            //全选
            $('input[type="checkbox"].list_item').bind('click', function () {
                var status = $(this).is(':checked'),
                    groupName = $(this).attr('name'),
                    checkbox_all = $('input[type="checkbox"][name="' + groupName + '"].list_all');

                if (!status) {
                    checkbox_all.removeAttr('checked');
                }

            });

            //如果选中所有checkbox则全选也选中
            $('input[type="checkbox"].list_all').each(function () {
                var groupName = $(this).attr('name');
                var item = $('input[type="checkbox"][name="' + groupName + '"].list_item');
                if (item.length == item.filter(':checked').length) {
                    $(this).attr('checked', true);
                } else {
                    $(this).removeAttr('checked');
                }
            });

        });
    </script>
</head>

@using Wicresoft.UnifyShow.Utility;
@using Wicresoft.UnifyShow.Business;

@{
    var allMonth = new string[] { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
    var planType = ViewData["PlanType"] as EnumDataSource<EnumUtility.PlanType>;
    var currentUser = ViewBag.CurrentUser as User_XModel;

    //详情数据
    var Model = ViewData["Model"] as ScheduleJob;
    var isView = Model != null && Model.Job != null;
    var job = isView ? Model.Job : null;
    var cycleList = isView ? Model.Cycle : null;
    var cycle = (isView && cycleList != null && cycleList.Count() > 0) ? Model.Cycle.FirstOrDefault() : null;
    var selectedMonth = (isView && cycleList != null && cycleList.Count() > 0) ? cycleList.Select(x => x.Month).ToList() : null;

    //创建人可以编辑计划
    var canEdit = (isView && currentUser.ID == job.JobOwnerID) || !isView;

}

<body>
    <div class="padding20" style="width: 840px; margin: 0 auto;" id="planDetail">
        <input type="hidden" id="detailID" value="@(ViewBag.DetailID)" />
        <input type="hidden" id="canEdit" value="@(canEdit)" />
        <div class="buttonContainer">
            <input type="button" value="保存" onclick="planValidate(this);" id="btnSave" @(canEdit ? "" : "disabled='disabled'") />
            <input type="button" value="取消" onclick="closeWindow();" id="btnCancel" @(canEdit ? "" : "disabled='disabled'") />
        </div>

        <div class="parameter">
            <div class="parameter_name">
                <span class="required">*</span>
                @RenderSection("Name", required: true)
            </div>
            <div class="parameter_input">
                <input type="text" id="InspTitle" @(canEdit ? "" : "disabled='disabled'") value="@(isView ? job.JobName : "")" data-required-info="请填写巡检名称!" data-model-source="JobName" />
            </div>
        </div>

        <div class="parameter">
            <div class="parameter_name">@RenderSection("Description", required: true)</div>
            <div class="parameter_input">
                <textarea @(canEdit ? "" : "disabled='disabled'") id="JobDesc" rows="6" data-model-source="JobDescription">@(isView ? job.JobDescription : "")</textarea>
            </div>
        </div>

        @*第三方巡检类型*@
        @RenderSection("ThirdInspectionType", required: false)

        @*责任人*@
        @RenderSection("Responsible", required: false)

        <div class="parameter">
            <div class="parameter_name">
                <span class="required">*</span>
                创建人：
            </div>
            <div class="parameter_input short">
                <input type="text" disabled="disabled" id="creator" data-required-info="请填写创建人!" value="@(isView ? job.JobOwnerName : currentUser.DisplayName)" />
                <input type="hidden" id="creatorID" data-model-source="JobOwnerID" value="@(isView ? job.JobOwnerID : currentUser.ID)" />
            </div>
        </div>

        <div class="parameter_name">
            @RenderSection("CycleTitle", required: true)
        </div>
        <div>
            <table id="InspectionCycle" class="outer_border" cellpadding="0" cellspacing="1" style="width: 820px;">
                <tr>
                    <td class="left">
                        <table id="cycle" style="width: 100%;">
                            @{var cycleType = cycle != null ? cycle.PlanType : 0;}
                            @for (var i = 0; i < planType.Count; i++)
                            {
                                var type = planType[i];
                                <tr>
                                    <td>
                                        <input type="radio" data-panel="detail_@(type.EnumValue)" name="cycle" value="@(type.EnumValue)" id="cycle_@(type.EnumValue)" @(((isView && cycleType == type.EnumValue) || (!isView && i == 0)) ? "checked='checked'" : "") />
                                        <label for="cycle_@(type.EnumValue)">@(type.DisplayValue)</label>
                                    </td>
                                </tr>
                            }
                        </table>
                    </td>
                    <td class="right" style="vertical-align: top;">
                        <table id="detail_1" class="cycle_detail">
                            <tr>
                                <td>
                                    <div class="parameter_name">
                                        <span class="required">*</span>
                                        开始时间：<input type="text" value="@((isView && cycle != null) ? (cycle.BeginDate != DateTime.MinValue ? cycle.BeginDate.ToString("yyyy-MM-dd") : "") : "")" class="easyui-datebox startDate" data-required-info="请选择周期开始时间!" data-group="Once" id="startDate_Once" />
                                    </div>
                                    <div class="parameter_name">
                                        <span class="required">*</span>
                                        结束时间：<input type="text" value="@((isView && cycle != null) ? (cycle.EndDate != DateTime.MinValue ? cycle.EndDate.ToString("yyyy-MM-dd") : "") : "")" class="easyui-datebox endDate" data-required-info="请选择周期结束时间!" data-group="Once" id="endDate_Once" />
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <table id="detail_2" style="display: none;" class="cycle_detail">
                            <tr>
                                <td>
                                    <div class="parameter_name">
                                        开始时间：<input type="text" value="@((isView && cycle != null) ? (cycle.BeginDate != DateTime.MinValue ? cycle.BeginDate.ToString("yyyy-MM-dd") : "") : "")" class="easyui-datebox startDate" data-required-info="请选择周期开始时间!" data-group="Day" id="startDate_Day" />
                                    </div>
                                    <div class="parameter_name">
                                        结束时间：<input type="text" value="@((isView && cycle != null) ? (cycle.EndDate != DateTime.MinValue ? cycle.EndDate.ToString("yyyy-MM-dd") : "") : "")" class="easyui-datebox endDate" data-group="Day" id="endDate_Day" />
                                    </div>
                                    <div style="margin: 15px 40px;">
                                        <input type="checkbox" id="excludeWeekend" @((isView && cycle != null && cycle.HolidayInValid == 1) ? "checked='ckecked'" : "") />
                                        <label for="excludeWeekend" class="parameter_name" style="font-size: 12px;">周六周日除外</label>
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <table id="detail_3" style="display: none;" class="cycle_detail">
                            <tr>
                                <td>
                                    <div class="parameter_name">
                                        开始时间：<input type="text" value="@((isView && cycle != null) ? (cycle.BeginDate != DateTime.MinValue ? cycle.BeginDate.ToString("yyyy-MM-dd") : "") : "")"  class="easyui-datebox startDate" data-required-info="请选择周期开始时间!" data-group="Week" id="startDate_Week" />
                                    </div>
                                    <div class="parameter_name">
                                        结束时间：<input type="text" value="@((isView && cycle != null) ? (cycle.EndDate != DateTime.MinValue ? cycle.EndDate.ToString("yyyy-MM-dd") : "") : "")"  class="easyui-datebox endDate" data-group="Week" id="endDate_Week" />
                                    </div>
                                    <div style="margin: 15px 40px;">
                                        <input type="radio" id="week_1" @(isView && cycle != null && cycle.Day == 1 ? "checked='checked'" : "") name="week" data-required-info="请选择周期具体触发时间!" value="1" />
                                        <label for="week_1">星期一</label>
                                        @for (var i = 2; i <= 7; i++)
                                        {
                                            <input type="radio" id="week_@(i)" name="week" value="@i" @(isView && cycle != null && cycle.Day == i ? "checked='checked'" : "") />
                                            <label for="week_@(i)">星期@(allMonth[i - 1])</label>
                                        }
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <table id="detail_4" style="display: none;" class="cycle_detail">
                            <tr>
                                <td>
                                    <div class="parameter_name">
                                        开始时间：<input type="text" value="@((isView && cycle != null) ? (cycle.BeginDate != DateTime.MinValue ? cycle.BeginDate.ToString("yyyy-MM-dd") : "") : "")" class="easyui-datebox startDate" data-required-info="请选择周期开始时间!" data-group="Month" id="startDate_Month" />
                                    </div>
                                    <div class="parameter_name">
                                        结束时间：<input type="text" value="@((isView && cycle != null) ? (cycle.EndDate != DateTime.MinValue ? cycle.EndDate.ToString("yyyy-MM-dd") : "") : "")" class="easyui-datebox endDate" data-group="Month" id="endDate_Month" />
                                        <input type="checkbox" onclick="toggleChooseDay();" id="chooseDays" @(isView && cycle != null && cycle.IsLengthValid == 1 ? "checked='checked'" : "") />
                                        <label for="chooseDays">单次任务持续天数</label>
                                        <input type="number" max="30" min="1" value="@((isView && cycle != null) ? cycle.Length : 1)" id="numberRange" />
                                    </div>
                                    <div style="height: 45px;">
                                        <span class="parameter_name">月：</span>

                                        <input type="checkbox" id="checkAll" class="list_all" name="month" data-required-info="请选择周期触发月份!" />
                                        <label for="checkAll">全选</label>
                                        <div style="display: inline-block; *display: inline; *zoom: 1; float: right; width: 84%; *margin-top: -20px;" id="monthSelectList">
                                            @for (var i = 0; i < allMonth.Length; i++)
                                            { 
                                                <input type="checkbox" id="month_@(i + 1)" name="month" class="list_item" value="@(i + 1)" @((isView && selectedMonth != null && selectedMonth.Contains(i + 1)) ? "checked='checked'" : "")/>
                                                <label for="month_@(i + 1)">@(allMonth[i] + "月")</label>
                                            }
                                        </div>
                                    </div>
                                    <div style="height: 80px;">
                                        <span class="parameter_name">天：</span>
                                        <div style="display: inline-block; width: 86%; *display: inline; *zoom: 1;">
                                            <input type="radio" id="day_1" name="dayList" data-required-info="请选择周期触发日期!" value="1" @((isView && cycle != null && cycle.Day == 1) ? "checked='checked'" : "") />
                                            <label for="day_1">1</label>
                                            @for (var i = 1; i <= 30; i++)
                                            { 
                                                <input type="radio" id="day_@(i + 1)" name="dayList" value="@(i + 1)" @((isView && cycle != null && cycle.IsLastDay != 1 && cycle.Day == (i + 1)) ? "checked='checked'" : "") />
                                                <label for="day_@(i + 1)">@(i + 1)</label>
                                            }
                                            <input type="radio" id="day_last" name="dayList" value="31" @((isView && cycle != null && cycle.Day == 31 && cycle.IsLastDay == 1) ? "checked='checked'" : "") />
                                            <label for="day_last">最后一天</label>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>

        @*巡检范围*@
        @RenderSection("InspectionRange", required: false)

        <div class="parameter_name">
            <input type="radio" name="usingGroup" id="start" @(((isView && job.Invalid == 1)) ? "checked='checked'" : "") @(canEdit ? "" : "disabled='disabled'") />
            <label for="start">启用</label>
            <input type="radio" name="usingGroup" id="pause" @(((isView && job.Invalid == 0) || !isView) ? "checked='checked'" : "") @(canEdit ? "" : "disabled='disabled'") />
            <label for="pause">暂停</label>
            <label></label>
        </div>

        @*巡检对象*@
        @RenderSection("InspectionObject", required: false)

        @*相关文件*@
        @RenderSection("FileUpload", required: false)

        @*电子公告*@
        @RenderSection("ElectronicBulletin", required: false)

        @RenderBody()
    </div>

    @if (isView)
    { 
       
        <script type="text/javascript">

            var disabledControl = function (excludeControlIDs) {

                var controls = $('body').find('input,select,textarea');
                controls.each(function () {
                    if ($.inArray($(this).attr('id'), excludeControlIDs) < 0) {
                        $(this).attr('disabled', true);
                    }
                });

                $('.easyui-datebox').datebox({ 'disabled': true });
                $('.validatebox-text').attr('disabled', true);
                $('.searchbox-button').hide();
            };


            $(function () {
                var canEdit = $('#canEdit').val() == "True";
                if (canEdit) {
                    disabledControl(['InspTitle', 'JobDesc', 'start', 'pause', 'btnSave', 'btnCancel', "InspRange"]);
                } else {
                    disabledControl();
                }
            });

        </script>
    }
    else
    {
        <script type="text/javascript">
            $(function () {
                $('.startDate').datebox('setValue', new Date().formate());
            });
        </script>
    }

</body>
</html>
